#include "stdafx.h"
#include "dllmain.h"

#pragma region Declarations
std::vector<LogFile *> logFiles;
#pragma endregion

#pragma region DllMain
/// <summary>
/// Defines the entry point for the DLL application.
/// </summary>
BOOL APIENTRY DllMain( HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
		Create();
		break;
	case DLL_THREAD_ATTACH:
		break;
	case DLL_THREAD_DETACH:
		break;
	case DLL_PROCESS_DETACH:
		Destroy();
		break;
	}
	return TRUE;
}
#pragma endregion

#pragma region Create
/// <summary>
/// Create the data structures that will be used to presist data between calls.
/// </summary>
void Create()
{

}
#pragma endregion

#pragma region Destroy
/// <summary>
/// Free memory which was allocaed.
/// </summary>
void Destroy()
{
	// remove references to log files
	for (long i = 0; i < (long)logFiles.size(); i++)
	{
		LogFile *logFile = logFiles.at(i);
		if (logFile != NULL)
		{
			delete logFile;
			logFile = NULL;
		}
	}

	logFiles.clear();
}
#pragma endregion


#pragma region Add Log File
/// <summary>
/// Add a log file and return the handle to the file.
/// </summary>
long AddLogFile(LogFile *logFile)
{
	logFiles.push_back(logFile);
	return logFiles.size();
}
#pragma endregion

#pragma region GetLogFile
/// <summary>
/// Get a log file by its handle.
/// </summary>
LogFile *GetLogFile(long handle)
{
	long index = handle - 1;
	if ((long)logFiles.size() > index)
	{
		return logFiles.at(index);
	}

	return NULL;
}
#pragma endregion

